package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealComtroller {
    @Autowired
    SetmealService setmealService;

    /**
     * 添加套餐
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @PostMapping("/add")
    public Result addSetmeal(@RequestBody Setmeal setmeal, @RequestParam("checkgroupIds") List<Integer> checkgroupIds) {
        setmealService.addSetmeal(setmeal, checkgroupIds);
        return new Result(true, "新增套餐成功");
    }

    /**
     * 删除套餐
     * @param id
     * @return
     */
    @GetMapping("/deleteById")
    public Result deleteById(Integer id) {
        setmealService.deleteById(id);
        return new Result(true, "删除套餐成功");
    }

    /**
     * 编辑套餐
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Setmeal setmeal, @RequestParam("checkgroupIds") List<Integer> checkgroupIds) {
        setmealService.addSetmeal(setmeal, checkgroupIds);
        return new Result(true, "编辑成功");
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(Integer id) {
        return new Result(true, "查询成功", setmealService.findById(id));
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return setmealService.findPage(queryPageBean);
    }
}
